﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Client_Revenue
{
    public partial class SalesTeam1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                setData();
            }
        }
        private void setData()
        {
            using (var DE = new dominiumEntities())
            {
                var salesInf = (from si in DE.SalesInfoes
                                join p in DE.People on si.PersonId equals p.PersonId
                                join co in DE.Contracts on si.ContractId equals co.ContractId
                                join cr in DE.ContractReceipts on co.ContractId equals cr.ContractId
                                join c in DE.Clients on co.ClientId equals c.ClientId
                                join r in DE.RevenueTypes on si.RevenueTypeId equals r.RevenueTypeId
                                select new {
                                            Name = p.FirstName + " " + p.LastName,
                                            c.ClientName,
                                            r.RevenueTypeName,
                                            si.Commission, 
                                            AmountAllocated = ((cr.ReceivedAmount * si.Commission)/100),
                                            si.Fee,
                                            cr.ReceiptDate
                                            }).Distinct().ToList();

                gvSalesInfo.DataSource = salesInf;
                gvSalesInfo.DataBind();
            }
        }

        protected void gvSalesInfo_SelectedIndexChanged(object sender, EventArgs e)
        {

        }


        protected void gvSalesInfo_PageIndexChanged(object sender, EventArgs e)
        {

        }

        protected void gvSalesInfo_RowEditing(object sender, GridViewEditEventArgs e)
        {

        }

        protected void gvSalesInfo_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {

        }

        protected void gvSalesInfo_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {

        }

        protected void gvSalesInfo_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {

        }
    }
}